package zoltan.balog.entities;

import java.util.Comparator;

public class Route {
	private City from;
	private City to;
	private double cost;

	public Route(City from, City to, double cost) {
		super();
		this.from = from;
		this.to = to;
		this.cost = cost;
	}

	public City getFrom() {
		return from;
	}

	public City getTo() {
		return to;
	}

	public double getCost() {
		return cost;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Route other = (Route) obj;
		if (Double.doubleToLongBits(cost) != Double
				.doubleToLongBits(other.cost))
			return false;
		if (from == null) {
			if (other.from != null)
				return false;
		} else if (!from.equals(other.from))
			return false;
		if (to == null) {
			if (other.to != null)
				return false;
		} else if (!to.equals(other.to))
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(cost);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((from == null) ? 0 : from.hashCode());
		result = prime * result + ((to == null) ? 0 : to.hashCode());
		return result;
	}

	@Override
	public String toString() {
		return "Route [from=" + from + ", to=" + to + ", cost=" + cost + "]";
	}

	public static class ReverseRouteComparator implements Comparator<Route> {

		@Override
		public int compare(Route o1, Route o2) {
			return (int) Math.signum(o2.getCost() - o1.getCost());
		}

	}
}
